let cardPoints = [1,2,3,4,5,6,1]
let k = 3
var maxScore = function(cardPoints, k) {
    let len = cardPoints.length
    let left = 0
    let right = len - k
    let sum = 0
    for(let i = right; i < len; i++) {
        sum += cardPoints[i]
    }
    let max = sum
    while(right < len) {
        sum += cardPoints[left]
        sum -= cardPoints[right]
        max = Math.max(max, sum)
        left++
        right++
    }
    return max

};
console.log(maxScore(cardPoints, k))
